from time import sleep

import page
from base.web_base import WebBase


class PageMailWriteLetter(WebBase):
    # 点击写信
    def page_click_write_letter(self):
        self.base_click(page.write_letter_button)

    # 切换main_iframe
    def page_switch_main_iframe(self):
        self.base_switch_iframe(page.main_iframe)
        sleep(5)

    # 输入收件人
    def page_input_recipient(self, recipient):
        self.base_input(page.recipient, recipient)

    # 输入主题
    def page_input_subject(self, subject):
        self.base_input(page.subject, subject)

    # 输入正文
    def page_input_content(self, content):
        # 1.切换iframe
        iframe = self.base_find(page.content_iframe)
        self.base_switch_iframe(iframe)
        sleep(1.5)
        self.base_click(page.content)
        # 2.输入内容
        self.base_input(page.content, content)
        sleep(1.5)
        # 3.回到默认目录
        self.base_switch_default_iframe()
        # 4. 进入main_iframe目录
        sleep(3)
        self.base_switch_iframe(page.main_iframe)
        sleep(3)

    # 选择发件人
    def page_choose_sender(self):
        # 1.调用WebBase封装方法
        self.web_base_click_element(page.sender_father, page.send_child)

    # 点击发送
    def page_click_send(self):
        self.base_click(page.send_button)

    # 获取写信提示信息
    def page_get_info(self):
        return self.base_get_text(page.success_info)

    # 组合写信业务方法
    def page_write_letter(self, recipient, subject, content):
        self.page_click_write_letter()
        self.page_switch_main_iframe()
        self.page_input_recipient(recipient)
        self.page_input_subject(subject)
        self.page_input_content(content)
        self.page_choose_sender()
        self.page_click_send()
